/*******************************************************************************
*funtion: 
*date	:	
*author	:
*modify	:
*note	:
*******************************************************************************/

#include "GuardServer.h"


GuardServer::GuardServer()
{
	printf("GuardServer::GuardServer()\n");
}

GuardServer::~GuardServer()
{
	logger().information("GuardServer::~GuardServer()!");

}

void GuardServer::initLog(const string& path)
{
	//init Format Property for log
	PatternFormatter* pPatter = new PatternFormatter("%Y-%m-%d %H:%M:%S.%i [%P:%I]:%q:%t");

	FormattingChannel* pFCConsole = new FormattingChannel(pPatter);
	pFCConsole->setChannel(new ConsoleChannel);
	pFCConsole->open();
	
	
	//FormattingChannel* pFCFile = new FormattingChannel(new PatternFormatter("%Y-%m-%e %H:%M:%S.%i [%P:%T]:%q:%t"));
	FormattingChannel* pFCFile = new FormattingChannel(pPatter);
	pPatter->setProperty(PatternFormatter::PROP_TIMES,"local");

	//init File Property for log
	FileChannel *pFile = new FileChannel(path);
	//reserver file size of each log file
	pFile->setProperty(FileChannel::PROP_ROTATION,"1 K");
	//pFile->setProperty(FileChannel::PROP_COMPRESS,"true");
	//pFile->setProperty(FileChannel::PROP_ARCHIVE,"number");
	//file name by timestamp,eg as.log.20130227165009712
	pFile->setProperty(FileChannel::PROP_TIMES,"local");
	pFile->setProperty(FileChannel::PROP_ARCHIVE,"timestamp");
	//reserver file time
	pFile->setProperty(FileChannel::PROP_PURGEAGE,"1 days");
	//reserve file count,except as.log
	pFile->setProperty(FileChannel::PROP_PURGECOUNT,"2");

	pFCFile->setChannel(pFile);
	AsyncChannel* pAsyncFile = new AsyncChannel(pFCFile);
//	pAsyncFile->open();
	AsyncChannel* pAsyncConsole = new AsyncChannel(pFCConsole);
//	pAsyncConsole->open();

	SplitterChannel* pSplitter = new SplitterChannel;
	pSplitter->addChannel(pAsyncFile);
	pSplitter->addChannel(pAsyncConsole);
	//pSplitter->addChannel(pFCConsole);if not async,call this

	logger().setChannel(pSplitter);
	logger().setLevel(Message::PRIO_INFORMATION);
	logger().information("GuardServer::GuardServer()!");
}

